import com.itheima.dao.UserService;
import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

import java.util.logging.XMLFormatter;

public class demo01 {
    @Test
    public void test01() {

       /* ApplicationContext ctx= new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = (UserService) ctx.getBean("userService");
        userService.add();
        String S = userService.getName("xiaojiang");*/

        //ApplicationContext接口 立刻加载
       ApplicationContext context = new FileSystemXmlApplicationContext("D:\\jdbc\\day01_ssmspring\\day01_1\\src\\main\\resources\\applicationContext.xml");
        UserService userService = context.getBean("userService", UserService.class);

        userService.add();


    }
    //构造方法加载
    @Test
    public  void tset02() {
        ClassPathResource classPathResource = new ClassPathResource("applicationContext.xml");
        //根接口 延迟加载
        XmlBeanFactory formatter = new XmlBeanFactory(classPathResource);
       UserService userService = (UserService) formatter.getBean("userService");
       userService.add();


    }
    //静态工厂类加载
    @Test
    public void test03() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService1 = context.getBean("userService1", UserService.class);
        userService1.add();

    }

    //非静态工厂加载
    @Test
    public void tset04() {
         ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService1 = context.getBean("userService3", UserService.class);
        userService1.add();

    }


}
